package com.scau.ums.service.imp.info;

import com.github.pagehelper.PageHelper;
import com.scau.ums.mapper.CustomedInfoMapper;
import com.scau.ums.mapper.InfoMapper;
import com.scau.ums.model.Info;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InfoImp {

    @Autowired
    private CustomedInfoMapper customedInfoMapper;

    private InfoMapper infoMapper;

    public List<Info>  getUncheckedInfoList(String receiverId,Integer currentInfoPage){
        PageHelper.startPage(currentInfoPage,5);
        return  customedInfoMapper.getUncheckedInfoList(receiverId);
    }

    public List<Info> getAllInfoList(String receiverId,Integer currentInfoPage){
        PageHelper.startPage(currentInfoPage,6);
        return  customedInfoMapper.getAllInfoList(receiverId);
    }

    public Info getSpecifiedInfo(Integer InfoId){
        return  customedInfoMapper.getSpecifiedInfo(InfoId);
    }



    public void InfoIsChecked(Integer InfoId){
        customedInfoMapper.InfoIsChecked(InfoId);
    }

    public List<Info> getLatestInfoListByReceiverId(String receiverId,int startIndex,int pageSize){
        String whereClause="receiver_id="+receiverId;
        return customedInfoMapper.getLatestInfoList("Info","date DESC",startIndex,pageSize,whereClause);
    }

    public int updateInfoState(int infoId){
        Info info=infoMapper.selectByPrimaryKey(infoId);
        return infoMapper.updateByPrimaryKey(info);
    }

    public int countUncheckedInfo(String receiverId){
        int unCheckedSum=customedInfoMapper.countUncheckedInfo(receiverId);
        return unCheckedSum;
    }
}
